const express = require('express');
const router = express.Router();

router.get('/forCurrentUser', (req, res) => {
    const content = [];
    for(let i = 0; i < 40; i++) content.push({
        id: `${i}`,
        partSaleOrderId: `partSaleOrderId${i}`,
        partOrderCode: `partOrderCode${i}`,
        status: 1,
        code: `code${i}`,
        brandCode: 'brandCode',
        dealerCode: `dealerCode${i}`,
        country: `country${i}`,
        // eslint-disable-next-line no-nested-ternary
        partSaleOrderStatus: (i % 5 === 0 ? 1 : (i % 2 === 0 ? 2 : -1)),
        customerOrderCode: `customerOrderCode${i}`,
        partOrderTypeName: `partOrderTypeName${i}`,
        partOrderPriceTerms: 1,
        paymentType: 2,
        transportType: 1,
        totalQuantity: 747,
        totalAmount: 4554,
        piAmount: 120,
        shipmentAmount: i + 100,
        insuranceAmount: i + 200,
        currency: i,
        submitTime: '2019-08-28 18:34:59',
        rowVersion: 'A11111111',
        options: ['update', 'confirm', 'abandon', 'audit', 'create', 'printExcel', 'printPdf', 'cancel']
    });

    res.json({
        message: 'ok',
        payload: {
            content,
            totalElements: 40,
        }
    });
});

router.get('/:id', (req, res) => {
    res.json(
        {
            message: 'string',
            payload: {
                id: '1',
                bankId: 'bankId',
                bankAccount: 'bankAccount',
                payableAccount: 'PayableAccount',
                shipmentAmount: 50,
                insuranceAmount: 25.4,
                carier: 'carier',
                comment: 'comment',
                status: 3,
                rowVersion: 'A11111111',
                options: ['update', 'confirm', 'abandon', 'audit', 'create', 'printExcel', 'printPdf', 'cancel'],
                partSaleOrder: {
                    id: 'string',
                    code: 'PPPSF222331',
                    brandId: 'brandId',
                    brandCode: 'brandCode',
                    brandName: 'brandName',
                    dealerId: 'dealerId',
                    dealerCode: 'qrgj',
                    dealerName: '奇瑞国际经销商',
                    submitTime: '2019-08-28 18:34:59',
                    country: '中国',
                    partOrderTypeId: 'partOrderTypeId',
                    partOrderTypeName: '销售订单类型11111',
                    paymentType: 1,
                    customerOrderCode: 'customerOrderCode',
                    receivedPerson: 'receivedPerson',
                    partOrderPriceTerms: 1,
                    receivedPersonPhone: '18864589125',
                    carier: 'carier',
                    receivedAddress: 'receivedAddress',
                    transportType: 2,
                    receivedPort: 'receivedPort',
                    currency: 3,
                    shipmentPort: 'shipmentPort',
                    remark: 'remark'
                },
                details: [{
                    id: '1',
                    partId: '1',
                    partCode: 'code1',
                    partName: '配件1',
                    newPartId: '4',
                    newPartCode: 'code4',
                    newPartName: '配件4',
                    price: null,
                    amount: 50,
                    quantity: 5,
                    isEstimated: true
                }, {
                    id: '2',
                    partId: '2',
                    partCode: 'code2',
                    partName: '配件2',
                    newPartId: '3',
                    newPartCode: 'code3',
                    newPartName: '配件3',
                    price: 10,
                    amount: 50,
                    quantity: 5,
                    isEstimated: true
                }],
                operationHistories: [{
                    id: '1',
                    operatorName: 'ds',
                    operateStatus: '生成',
                    operateTime: '2019-08-28 18:34:59'
                },
                {
                    id: '2',
                    operatorName: 'ds',
                    operateStatus: '调整',
                    operateTime: '2019-08-28 18:34:59'
                }],
                attachments: [{
                    fileId: 'te1232-131232-1we',
                    fileName: '安装背景图1'
                },
                {
                    fileId: 'qww1-232131-12e',
                    fileName: '安装背景图2'
                }]
            }
        }
    );
});

router.put('/:id', (req, res) => {
    res.json({
        message: '编辑成功'
    });
});

router.post('/', (req, res) => {
    res.json({
        message: '新增成功'
    });
});

router.put('/:id/abandon', (req, res) => {
    res.json({
        message: '作废成功'
    });
});

router.put('/:id/cancel', (req, res) => {
    res.json({
        message: '取消成功'
    });
});

router.put('/:id/confirm', (req, res) => {
    res.json({
        message: '确认成功'
    });
});

router.put('/:id/audit', (req, res) => {
    res.json({
        message: '审核通过'
    });
});
router.get('/:id/exportExcel', (req, res) => {
    res.json({
        message: '下载Excel',
        payload: '1'
    });
});
module.exports = router;
